// components/goods-diy/youhui/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    mch_id: {
      type: Number,
      value: 0
    },
    __wxapp_img: {
      type: Object,
      value: null
    },
    __user_info: {
      type: Object,
      value: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    coupon: [],
    show_coupon: !1
  },
  ready: function () {
    this.getInfo()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getInfo: function () {
      var that = this;
      var shop = wx.getStorageSync('address_info');
      var shop_id = shop && shop.shop_id ? shop.shop_id : 0
      var item = {
        name: 'coupon',
        shop_id: shop_id,
        mch_id: that.properties.mch_id
      };
      getApp().request({
        url: getApp().api.index.get_diy_info,
        data: item,
        success: function(t) {
          that.setData({
            coupon : t.data.list
          })
          
        },
        complete: function() {
          
        }
      })
    },
    updateCoupon: function () {
      this.triggerEvent('showGetCoupon')
    },
    receive: function(t) {
      var user = this.properties.__user_info;
      if (!user) {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        })
        return
      }
      var o = this, e = t.target.dataset.id,index= t.target.dataset.index;
      wx.showLoading({
          mask: !0
      }), getApp().request({
          url: getApp().api.coupon.receive,
          data: {
              id: e
          },
          success: function(t) {
            if (t.code == 0) {
              var coupon = o.data.coupon;
              coupon[index].is_receive = 1;
              o.setData({
                coupon: coupon
              });
            }
          },
          complete: function() {
              wx.hideLoading();
          }
      });
  },
  }
})
